package com.icoolkj.mall.order.controller;

import com.icoolkj.mall.common.Result;
import com.icoolkj.mall.order.dto.OrderRequest;
import com.icoolkj.mall.order.model.Order;
import com.icoolkj.mall.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author icoolkj
 * @version 1.0
 * @description
 * @createDate 2025/01/16 14:41
 */
//@CrossOrigin
@RestController
@RequestMapping("/api/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/create-order")
    public Result<?> createOrder(@RequestBody OrderRequest orderRequest){
        try {
           return orderService.createOrder(orderRequest.getUserId(), orderRequest.getProductId(), orderRequest.getOrderQuantity());
        } catch (RuntimeException e) {
            return Result.fail(e.getMessage());
        }
    }

}
